package com.atguigu.yygh.order.service.impl;

import com.atguigu.yygh.model.order.OrderCount;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.mapper.OrderCountMapper;
import com.atguigu.yygh.order.mapper.OrderMapper;
import com.atguigu.yygh.order.service.OrderCountService;
import com.atguigu.yygh.order.service.OrderService;
import com.atguigu.yygh.vo.order.OrderCountQueryVo;
import com.atguigu.yygh.vo.order.OrderCountVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class OrderCountServiceImpl extends
        ServiceImpl<OrderCountMapper, OrderCount> implements OrderCountService {
    @Override
    public Map<String,Object> selectOrderCount(OrderCountQueryVo orderCountQueryVo) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if(orderCountQueryVo.getHosname()!="" && orderCountQueryVo.getHosname()!=null){
            queryWrapper.eq("hosname", orderCountQueryVo.getHosname());
        }
        if(orderCountQueryVo.getReserveDateBegin() != null && orderCountQueryVo.getReserveDateBegin() !=""){
            queryWrapper.ge("reserve_date", orderCountQueryVo.getReserveDateBegin());
        }
        if(orderCountQueryVo.getReserveDateEnd() != null && orderCountQueryVo.getReserveDateEnd() !=""){
            queryWrapper.le("reserve_date", orderCountQueryVo.getReserveDateEnd());
        }
        List<OrderCount> orderCountVoList=  baseMapper.selectList(queryWrapper);

        //获取x需要数据 ，日期数据  list集合
        List<String> dateList = orderCountVoList.stream().map(OrderCount::getReserveDate).collect(Collectors.toList());

        //获取y需要数据，具体数量  list集合
        List<Integer> countList =orderCountVoList.stream().map(OrderCount::getCount).collect(Collectors.toList());

        Map<String,Object> map = new HashMap<>();
        map.put("dateList",dateList);
        map.put("countList",countList);
      return   map;
    }
}
